package com.szwistar.common.comm.jsonrpc;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;

/**
 * JSON-RPC 调用消息
 * 接收端接收到调用消息后，必须返回调用结果
 */
@JsonInclude(value=Include.NON_NULL)
public class JsonRpcMessageCall extends JsonRpcMessageAuthorizedRequest {
	// 发送时的时间戳(ms)
	protected long ms = System.currentTimeMillis();
	// 不做为协议字段传送，仅做为本地判断调用的耗时
	@JsonIgnore public long getMs() { return ms; }

	public JsonRpcMessageCall() {
		super();
		this.msgType = MSG_CALL;
	}

    public JsonRpcMessageCall(String from, String token, String method, String params) {
		super(MSG_CALL, from, token, method, params);
	}

	@Override
	public String toString() {
		String msg = "";
		if(params != null) { msg = (params.length() < 96) ? params : params.substring(0, 96) + " ..."; }
		return String.format("JsonRpcMessageCall [%s:'%s', token=%s, from=%s]", method, msg, token, from);
	}
}
